package com.sh.aspect;

import com.sh.common.context.AppContextHolder;
import com.sh.common.exception.BizException;
import com.sh.enums.BizCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class AdminPermissionCheckAspect {

    @Pointcut("execution(* com.sh.controller.admin..*.*(..))")
    public void adminPermission()  {

    }

    @Before("adminPermission()")
    public void adminPermissionCheck(JoinPoint point) throws BizException {
        log.info("start to check admin permission!");
        Boolean isAdmin= AppContextHolder.getAdmin();
        if(!isAdmin){
            throw new BizException(BizCodeEnum.PERMISSION_FAIL);
        }
    }
}
